<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <h1>
        <a href="search.html">搜索中心</a>
        <a id="login" href="login.html">登录</a>
        <div id="username" style="display:none">
            <a href="#"></a>
            <button id="logout">退出</button>
        </div>
    </h1>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.js"></script>
    <script>
        if (document.cookie) {
            var username = $.cookie("username")
            if (username) {
                $("#login").hide()
                $("#username").show().find("a").text(username)
            }

            $("#logout").click(function () {
                $.removeCookie("username")
                location.reload()
            })
        }
    </script>
</body>

</html>